<?php

	// TITLE: For_project AUTO MODEL
	// FILE: scaffolding/model/for_project.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createForProject = function($con, $forProject) {
		$sql = 'INSERT INTO for_project (project_id, donation_id) VALUES (';
		$sql .= $for_project->getProjectId() . ', ';
		$sql .= $for_project->getDonationId() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readForProject = function($con, $id) {
		$sql = 'SELECT * FROM for_project WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$forProject = new ForProject();
			$forProject->setProjectId($dbio->select($readProject(result[0])));
			$forProject->setDonationId($dbio->select($readDonation(result[1])));
		} else {
			$forProject = false;
		}
		return $forProject;
	};

	$updateForProject = function($con, $forProject) {
		$sql = 'UPDATE for_project SET ';
		$sql .= 'project_id = ' . $for_project->getProjectId() . ', ';
		$sql .= 'donation_id = ' . $for_project->getDonationId() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteForProject = function($con, $id) {
		$sql = 'DELETE FROM for_project WHERE project_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listForProject = function($con) {
		$sql = 'SELECT * FROM for_project';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$forProjects = array();
			while ($result = mysqli_fetch_array($results)) {
				$forProject = new ForProject();
				$forProject->setProjectId($dbio->select($readProject(result[0])));
				$forProject->setDonationId($dbio->select($readDonation(result[1])));
				$forProjects[] = forProject;
			}// end while
		} else {
			$forProjects = false;
		}
		return $forProjects;
	};

